package o;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningTaskInfo;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Rect;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.Display;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.MarginLayoutParams;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.LinearLayout.LayoutParams;
import androidx.annotation.NonNull;
import com.huawei.fastengine.fastview.download.utils.UiHelper;
import java.util.List;
import o.dky.c;

public final class epv {
    private static DisplayMetrics ˋ;
    private static int ˏ = -1;

    private static DisplayMetrics ͺ(Context context) {
        DisplayMetrics displayMetrics = new DisplayMetrics();
        if (context != null) {
            WindowManager windowManager = (WindowManager) context.getSystemService("window");
            if (windowManager != null) {
                Display defaultDisplay = windowManager.getDefaultDisplay();
                if (defaultDisplay != null) {
                    defaultDisplay.getMetrics(displayMetrics);
                }
            }
        }
        return displayMetrics;
    }

    private static DisplayMetrics ˊॱ(Context context) {
        DisplayMetrics displayMetrics = new DisplayMetrics();
        if (context == null) {
            return displayMetrics;
        }
        Display defaultDisplay = ((WindowManager) context.getSystemService("window")).getDefaultDisplay();
        try {
            Class.forName("android.view.Display").getMethod("getRealMetrics", new Class[]{DisplayMetrics.class}).invoke(defaultDisplay, new Object[]{displayMetrics});
        } catch (Exception e) {
            Logger.ˋ(UiHelper.TAG, "get full display metrics error!" + e.toString());
        }
        return displayMetrics;
    }

    public static int ˊ(Context context) {
        return ˊॱ(context).widthPixels;
    }

    public static int ˋ(Context context) {
        if (ˏ == -1) {
            try {
                Class cls = Class.forName("com.android.internal.R$dimen");
                ˏ = context.getResources().getDimensionPixelSize(((Integer) cls.getField("status_bar_height").get(cls.newInstance())).intValue());
            } catch (ClassNotFoundException e) {
                ˏ = 0;
                Logger.ˋ(UiHelper.TAG, "get status_bar_height ClassNotFoundException , " + e.toString());
            } catch (InstantiationException e2) {
                ˏ = 0;
                Logger.ˋ(UiHelper.TAG, "get status_bar_height InstantiationException , " + e2.toString());
            } catch (IllegalAccessException e3) {
                ˏ = 0;
                Logger.ˋ(UiHelper.TAG, "get status_bar_height IllegalAccessException , " + e3.toString());
            } catch (NoSuchFieldException e4) {
                ˏ = 0;
                Logger.ˋ(UiHelper.TAG, "get status_bar_height NoSuchFieldException , " + e4.toString());
            }
        }
        return ˏ;
    }

    public static int ˎ(@NonNull Resources resources) {
        int identifier = resources.getIdentifier("navigation_bar_height", "dimen", "android");
        return identifier > 0 ? resources.getDimensionPixelSize(identifier) : 0;
    }

    public static int ˎ(Context context) {
        if (ˋ == null) {
            ˋ = ͺ(context);
        }
        int i = ˋ.widthPixels;
        int i2 = ˋ.heightPixels;
        return i < i2 ? i : i2;
    }

    public static int ˏ(Context context) {
        if (ˋ == null) {
            ˋ = ͺ(context);
        }
        int i = ˋ.widthPixels;
        int i2 = ˋ.heightPixels;
        return i < i2 ? i2 : i;
    }

    public static int ॱ(Context context) {
        return ͺ(context).heightPixels;
    }

    public static void ॱ(Context context, View view) {
        if (view != null) {
            try {
                ((InputMethodManager) context.getSystemService("input_method")).hideSoftInputFromWindow(view.getWindowToken(), 0);
            } catch (Exception e) {
                Logger.ˋ("UiHelper hideSoftInput", "e = " + e.toString());
            }
        }
    }

    public static boolean ˎ() {
        String ˋ = dod.ˋ("ro.build.version.emui");
        if (ˋ == null || ˋ.trim().equals("")) {
            return false;
        }
        return true;
    }

    public static int ˋ(Context context, int i) {
        if (ˋ == null) {
            ˋ = ͺ(context);
        }
        return (int) (((float) i) * ˋ.density);
    }

    public static int ˎ(Context context, float f) {
        if (ˋ == null) {
            ˋ = ͺ(context);
        }
        return (int) ((f / ˋ.density) + 0.5f);
    }

    public static int ॱ(Context context, int i) {
        if (ˋ == null) {
            ˋ = ͺ(context);
        }
        return (int) TypedValue.applyDimension(2, (float) i, ˋ);
    }

    public static boolean ᐝ(Context context) {
        String packageName = ContentManager.getInstant().getContext().getPackageName();
        List runningTasks = ((ActivityManager) context.getSystemService("activity")).getRunningTasks(1);
        if (runningTasks == null || runningTasks.size() <= 0 || !packageName.equals(((RunningTaskInfo) runningTasks.get(0)).topActivity.getPackageName())) {
            return false;
        }
        return true;
    }

    public static boolean ˎ(Context context, int i) {
        try {
            List runningTasks = ((ActivityManager) context.getSystemService("activity")).getRunningTasks(1);
            if (!CollectCheck.isEmpty(runningTasks)) {
                RunningTaskInfo runningTaskInfo = (RunningTaskInfo) runningTasks.get(0);
                if (runningTaskInfo != null) {
                    Logger.ˎ(UiHelper.TAG, "checkActivityCount, numActivities:" + runningTaskInfo.numActivities + ", maxCount:" + i + "，topActivity:" + runningTaskInfo.topActivity.getClassName() + ", curContext:" + context.getClass().getName());
                    if (runningTaskInfo.numActivities > i && runningTaskInfo.topActivity.getClassName().equals(context.getClass().getName())) {
                        return true;
                    }
                }
            }
        } catch (Throwable e) {
            Logger.ˋ(UiHelper.TAG, "checkActivityCount error", e);
        }
        return false;
    }

    public static int ॱ() {
        int identifier = ContentManager.getInstant().getContext().getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (identifier > 0) {
            return ContentManager.getInstant().getContext().getResources().getDimensionPixelSize(identifier);
        }
        return 0;
    }

    public static LayoutParams ˋ() {
        LayoutParams layoutParams = new LayoutParams(-1, -1);
        layoutParams.weight = 1.0f;
        return layoutParams;
    }

    public static void ˋ(Configuration configuration, Activity activity, View view, View... viewArr) {
        if (activity != null && view != null) {
            final int ॱ = ॱ(activity);
            final MarginLayoutParams marginLayoutParams = (MarginLayoutParams) view.getLayoutParams();
            final Activity activity2 = activity;
            final View[] viewArr2 = viewArr;
            final View view2 = view;
            view.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
                public void onGlobalLayout() {
                    int i = 0;
                    Rect rect = new Rect();
                    activity2.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
                    int i2 = 0;
                    for (View view : viewArr2) {
                        if (view != null) {
                            i2 += view.getHeight();
                        }
                    }
                    int measuredHeight = view2.getMeasuredHeight();
                    if (measuredHeight > 0) {
                        int i3 = rect.top;
                        if (activity2.getActionBar() != null) {
                            i = activity2.getResources().getDimensionPixelSize(c.ͺॱ);
                        }
                        marginLayoutParams.topMargin = ((((ॱ - measuredHeight) - i3) - i) - i2) / 2;
                        view2.setLayoutParams(marginLayoutParams);
                        view2.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                    }
                }
            });
        }
    }

    public static int ʽ(Context context) {
        DisplayMetrics ͺ = ͺ(context);
        int i = ͺ.widthPixels;
        int i2 = ͺ.heightPixels;
        return i < i2 ? i : i2;
    }

    public static void ˋ(Context context, View view) {
        if (view != null) {
            int ˎ;
            Object obj = context.getResources().getConfiguration().orientation == 2 ? 1 : null;
            if (!epr.ˎ().ॱॱ()) {
                ˎ = ˎ(context) - ˋ(context, 32);
            } else if (obj != null) {
                ˎ = (azb.ॱ(context) / 2) - ˋ(context, 48);
            } else {
                ˎ = ((azb.ॱ(context) * 3) / 4) - ˋ(context, 48);
            }
            ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
            layoutParams.width = ˎ;
            view.setLayoutParams(layoutParams);
        }
    }

    public static int ˏ() {
        return ContentManager.getInstant().getContext().getResources().getDimensionPixelSize(c.ͺॱ) + ॱ();
    }

    public static int ॱॱ(Context context) {
        return (ˎ(context) - (context.getResources().getDimensionPixelSize(c.ˎˏ) * 2)) / 4;
    }

    public static int ˊ(Context context, int i) {
        int ˎ = (ˎ(context) - azb.ˊ(context)) - azb.ˏ(context);
        if (i < 4) {
            return ˎ / 3;
        }
        if (i > 4) {
            return ˎ(context) / i;
        }
        return ˎ / 4;
    }

    public static int ʻ(@NonNull Context context) {
        return context.getResources().getDimensionPixelSize(c.ॱ);
    }

    public static int ˊ() {
        return ContentManager.getInstant().getContext().getResources().getDimensionPixelSize(c.ˊ);
    }

    public static int ᐝ() {
        Context ˋ = ContentManager.getInstant().getContext();
        return ˋ.getResources().getDimensionPixelSize(c.ˈ) + (azb.ˊ(ˋ) + ˊ());
    }

    public static int ॱॱ() {
        Context ˋ = ContentManager.getInstant().getContext();
        int dimensionPixelSize = ˋ.getResources().getDimensionPixelSize(c.ʽ);
        if (azb.ʼ(ˋ)) {
            return ˋ.getResources().getDimensionPixelSize(c.ˋॱ);
        }
        return dimensionPixelSize;
    }

    public static int ʻ() {
        Context ˋ = ContentManager.getInstant().getContext();
        if (!ʼ(ˋ)) {
            return ˋ.getResources().getDimensionPixelSize(c.ʽ);
        }
        if (azb.ʼ(ˋ)) {
            return ˋ.getResources().getDimensionPixelSize(c.ˏॱ);
        }
        return ˋ.getResources().getDimensionPixelSize(c.ॱˊ);
    }

    public static boolean ʼ(Context context) {
        return (epr.ˎ().ॱॱ() || azb.ˎ(context) || cdn.ॱॱ()) ? false : true;
    }

    public static boolean ˏॱ(Context context) {
        return epr.ˎ().ॱॱ() && azb.ˎ(context);
    }

    public static int ˎ(@NonNull Context context, int i, int i2) {
        return (((azb.ॱ(context) - chc.ˏ()) - chc.ॱ()) - ((i - 1) * i2)) / i;
    }

    public static float ʼ() {
        return 0.5625f;
    }

    public static float ʽ() {
        return 1.25f;
    }

    public static int ˏॱ() {
        Context ˋ = ContentManager.getInstant().getContext();
        return (int) ((ˋ.getResources().getDimension(c.ॱॱ) * ˋ.getResources().getDimension(c.ͺ)) / ˋ.getResources().getDimension(c.ˊ));
    }
}
